import 'dart:math';

import 'package:flutter/material.dart';
import 'package:kasax_demos2/entry/data_posts_test.dart';

class WrapDemo extends StatefulWidget {
  const WrapDemo({Key? key}) : super(key: key);

  @override
  _WrapDemoState createState() => _WrapDemoState();
}

class _WrapDemoState extends State<WrapDemo> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("WrapDemo"),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              child: Wrap(
                spacing: 8,
                runSpacing: 4,
                children: PostsDatas.TEST_POSTS
                    .map((e) => Chip(
                          avatar: CircleAvatar(
                            foregroundColor: Colors.green.shade800,
                            child: Text("${e.title.substring(0, 1)}"),
                          ),
                          label: Text(
                              "${e.description.substring(0, 5 + Random().nextInt(30))}"),
                        ))
                    .toList(),
              ),
            ),
            Divider(),
            Wrap(
              spacing: 8.0,
              runSpacing: 4.0,
              children: [
                Chip(
                  avatar: CircleAvatar(
                      backgroundColor: Colors.blue.shade900,
                      child: const Text('AH')),
                  label: const Text('Hamilton'),
                ),
                Chip(
                  avatar: CircleAvatar(
                      backgroundColor: Colors.blue.shade900,
                      child: const Text('ML')),
                  label: const Text('Lafayette'),
                ),
                Chip(
                  avatar: CircleAvatar(
                      backgroundColor: Colors.blue.shade900,
                      child: const Text('HM')),
                  label: const Text('Mulligan'),
                ),
                Chip(
                  avatar: CircleAvatar(
                      backgroundColor: Colors.blue.shade900,
                      child: const Text('JL')),
                  label: const Text('Laurens'),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}
